<?php //strip
/**
 * Renderer for odWpEshopPlugin.
 * 
 * @author Ondrej Donek <ondrejd@gmail.com>
 * @package odWpEshopPlugin
 * @version 0.1
 */
class odWpEshopPluginRenderer
{
	
	/**
	 * Renders eshop items for main eshop page.
	 *
	 * @param array $aEshopItems
	 * @param boolean $aRenderPaging
	 * @param odWpEshopPluginPager $aPager
	 * @return void
	 */
	static function renderEshopItems($aEshopItems = null, $aRenderPaging = false, $aPager = null) 
	{
		$eshop_items = (is_array($aEshopItems)) ? $aEshopItems : array();
		$total_count = count($eshop_items);
		$i = 0;
?>
	<?php if($aRenderPaging === true && !is_null($aPager)):?>
	<div class="info">
		<div class="doleva">
			<?php if($aPager->mCurrentPage > 1):?>
				<a href="<?php echo $aPager->getPreviousPageUrl();?>">&laquo; Předchozí stránka</a>
			<?php else:?>
				&laquo; Předchozí stránka
			<?php endif;?>
		</div>
		<div class="stredni">
			Strana <?php echo $aPager->mCurrentPage;?> / <?php echo $aPager->mTotalPagesCount;?>
		</div>
		<div class="doprava">
			<?php if($aPager->mCurrentPage < $aPager->mTotalPagesCount):?>
				<a href="<?php echo $aPager->getNextPageUrl();?>">Následující stránka &raquo;</a>
			<?php else:?>
				Následující stránka &raquo;
			<?php endif;?>
		</div>
	</div>
	<?php endif;?>
	<?php foreach($eshop_items as $item):?>
		<?php if($i == 0):?>
		<span class="karty">
		<?php endif;?>
			<span class="karta">
				<span class="obrazek">
					<a href="<?php echo $item['detail_url'];?>"><img src="<?php echo $item['image_url3'];?>" alt="<?php echo $item['title'];?>" /></a>
				</span>
				<span class="text">
					<strong><a href="<?php echo $item['detail_url'];?>"><?php echo $item['item_title'];?></a></strong><br/>
					<?php if(empty($item['item_title_orig'])):?>
					<strong>&nbsp;</strong><br/>
					<?php else:?>
					(<strong><?php echo $item['item_title_orig'];?></strong>)<br/>
					<?php endif;?>
					<i>Kategorie:</i> <?php echo $item['genre_categories'];?><br />
					<i>Jazyk:</i> <?php echo $item['item_language'];?><br />
					<i>Titulky:</i> <?php echo $item['item_subtitles'];?>
				</span>
			</span>
		<?php if($i == 2):?>
			<?php $i = 0;?>
		</span>
		<?php else:?>
			<?php $i = $i + 1;?>
		<?php endif;?>
	<?php endforeach;?>
	<?php if($aRenderPaging === true && !is_null($aPager)):?>
	<div class="info">
		<div class="doleva">
			<?php if($aPager->mCurrentPage > 1):?>
				<a href="<?php echo $aPager->getPreviousPageUrl();?>">&laquo; Předchozí stránka</a>
			<?php else:?>
				&laquo; Předchozí stránka
			<?php endif;?>
		</div>
		<div class="stredni">
			Strana <?php echo $aPager->mCurrentPage;?> / <?php echo $aPager->mTotalPagesCount;?>
		</div>
		<div class="doprava">
			<?php if($aPager->mCurrentPage < $aPager->mTotalPagesCount):?>
				<a href="<?php echo $aPager->getNextPageUrl();?>">Následující stránka &raquo;</a>
			<?php else:?>
				Následující stránka &raquo;
			<?php endif;?>
		</div>
	</div>
	<?php endif;?>
<?php 
	}
	
	/**
	 * Renders genre categories for main eshop page.
	 *
	 * @param array $aSelCat
	 * @return void
	 */
	static function renderGenreCategories($aSelCat = null) 
	{
?>
		<div class="kategorie">
			<h4>Kategorie<?php echo (is_null($aSelCat)) ? '' : ':&nbsp;' . $aSelCat['title'];?></h4>
			<p><?php echo odWpEshopPluginRenderer::renderGenreCategoriesAnchors(false, $aSelCat);?></p>
		</div>
<?php 
	}
	
	/**
	 * Renders char categories for main eshop page.
	 *
	 * @param string $aSelChar
	 * @return void
	 */
	static function renderCharCategories($aSelChar = null) 
	{
		global $od_eshop_wpplugin;
?>
		<div class="kategorie">
			<h4>Film dle počátečního písmena:</h4>
			<p>
				<a href="<?php echo $od_eshop_wpplugin->get_main_page_url();?>&amp;selchar=a"<?php if($aSelChar == 'a') { echo ' class="selected"'; }?>>A</a> &nbsp;|&nbsp; 
				<a href="<?php echo $od_eshop_wpplugin->get_main_page_url();?>&amp;selchar=b"<?php if($aSelChar == 'b') { echo ' class="selected"'; }?>>B</a> &nbsp;|&nbsp; 
				<a href="<?php echo $od_eshop_wpplugin->get_main_page_url();?>&amp;selchar=c"<?php if($aSelChar == 'c') { echo ' class="selected"'; }?>>C</a> &nbsp;|&nbsp; 
				<a href="<?php echo $od_eshop_wpplugin->get_main_page_url();?>&amp;selchar=d"<?php if($aSelChar == 'd') { echo ' class="selected"'; }?>>D</a> &nbsp;|&nbsp; 
				<a href="<?php echo $od_eshop_wpplugin->get_main_page_url();?>&amp;selchar=e"<?php if($aSelChar == 'e') { echo ' class="selected"'; }?>>E</a> &nbsp;|&nbsp; 
				<a href="<?php echo $od_eshop_wpplugin->get_main_page_url();?>&amp;selchar=f"<?php if($aSelChar == 'f') { echo ' class="selected"'; }?>>F</a> &nbsp;|&nbsp; 
				<a href="<?php echo $od_eshop_wpplugin->get_main_page_url();?>&amp;selchar=g"<?php if($aSelChar == 'g') { echo ' class="selected"'; }?>>G</a> &nbsp;|&nbsp; 
				<a href="<?php echo $od_eshop_wpplugin->get_main_page_url();?>&amp;selchar=h"<?php if($aSelChar == 'h') { echo ' class="selected"'; }?>>H</a> &nbsp;|&nbsp; 
				<a href="<?php echo $od_eshop_wpplugin->get_main_page_url();?>&amp;selchar=i"<?php if($aSelChar == 'i') { echo ' class="selected"'; }?>>I</a> &nbsp;|&nbsp; 
				<a href="<?php echo $od_eshop_wpplugin->get_main_page_url();?>&amp;selchar=j"<?php if($aSelChar == 'j') { echo ' class="selected"'; }?>>J</a> &nbsp;|&nbsp; 
				<a href="<?php echo $od_eshop_wpplugin->get_main_page_url();?>&amp;selchar=k"<?php if($aSelChar == 'k') { echo ' class="selected"'; }?>>K</a> &nbsp;|&nbsp; 
				<a href="<?php echo $od_eshop_wpplugin->get_main_page_url();?>&amp;selchar=l"<?php if($aSelChar == 'l') { echo ' class="selected"'; }?>>L</a> &nbsp;|&nbsp; 
				<a href="<?php echo $od_eshop_wpplugin->get_main_page_url();?>&amp;selchar=m"<?php if($aSelChar == 'm') { echo ' class="selected"'; }?>>M</a> &nbsp;|&nbsp; 
				<a href="<?php echo $od_eshop_wpplugin->get_main_page_url();?>&amp;selchar=n"<?php if($aSelChar == 'n') { echo ' class="selected"'; }?>>N</a> &nbsp;|&nbsp; 
				<a href="<?php echo $od_eshop_wpplugin->get_main_page_url();?>&amp;selchar=o"<?php if($aSelChar == 'o') { echo ' class="selected"'; }?>>O</a> &nbsp;|&nbsp; 
				<a href="<?php echo $od_eshop_wpplugin->get_main_page_url();?>&amp;selchar=p"<?php if($aSelChar == 'p') { echo ' class="selected"'; }?>>P</a> &nbsp;|&nbsp; 
				<a href="<?php echo $od_eshop_wpplugin->get_main_page_url();?>&amp;selchar=q"<?php if($aSelChar == 'q') { echo ' class="selected"'; }?>>Q</a> &nbsp;|&nbsp; 
				<a href="<?php echo $od_eshop_wpplugin->get_main_page_url();?>&amp;selchar=r"<?php if($aSelChar == 'r') { echo ' class="selected"'; }?>>R</a> &nbsp;|&nbsp; 
				<a href="<?php echo $od_eshop_wpplugin->get_main_page_url();?>&amp;selchar=s"<?php if($aSelChar == 's') { echo ' class="selected"'; }?>>S</a> &nbsp;|&nbsp; 
				<a href="<?php echo $od_eshop_wpplugin->get_main_page_url();?>&amp;selchar=t"<?php if($aSelChar == 't') { echo ' class="selected"'; }?>>T</a> &nbsp;|&nbsp; 
				<a href="<?php echo $od_eshop_wpplugin->get_main_page_url();?>&amp;selchar=u"<?php if($aSelChar == 'u') { echo ' class="selected"'; }?>>U</a> &nbsp;|&nbsp; 
				<a href="<?php echo $od_eshop_wpplugin->get_main_page_url();?>&amp;selchar=v"<?php if($aSelChar == 'v') { echo ' class="selected"'; }?>>V</a> &nbsp;|&nbsp; 
				<a href="<?php echo $od_eshop_wpplugin->get_main_page_url();?>&amp;selchar=w"<?php if($aSelChar == 'w') { echo ' class="selected"'; }?>>W</a> &nbsp;|&nbsp; 
				<a href="<?php echo $od_eshop_wpplugin->get_main_page_url();?>&amp;selchar=x"<?php if($aSelChar == 'x') { echo ' class="selected"'; }?>>X</a> &nbsp;|&nbsp; 
				<a href="<?php echo $od_eshop_wpplugin->get_main_page_url();?>&amp;selchar=y"<?php if($aSelChar == 'y') { echo ' class="selected"'; }?>>Y</a> &nbsp;|&nbsp; 
				<a href="<?php echo $od_eshop_wpplugin->get_main_page_url();?>&amp;selchar=z"<?php if($aSelChar == 'z') { echo ' class="selected"'; }?>>Z</a> &nbsp;|&nbsp; 
			</p>
		</div>
<?php 
	}
	
	/**
	 * Renders anchors with genre categories. (Used on main eshop page).
	 *
	 * @param boolen $aRenderList
	 * @param string $aSelectedCatId
	 * @return string
	 */
	static function renderGenreCategoriesAnchors($aRenderList = false, $aSelectedCatId = null) 
	{
		global $od_eshop_wpplugin;
		
		$ret = '';
		// TODO Move this into the odWpEshopPluginDbModel
		global $wpdb;
		$query1 = "SELECT * FROM `{$wpdb->prefix}eshop_genre_categories` WHERE 1 ORDER BY `title` ASC ";
		$categories = $wpdb->get_results($query1, ARRAY_A);
		//$categories = odWpEshopPluginDbModel::getGenreCategories();
	
		if(!$categories) {
			return ($aRenderList === true)
					? '<ul><li>Zatím nebyly vytvořeny žádné kategorie.</li></ul>'
					: '<p>Zatím nebyly vytvořeny žádné kategorie.</p>';
		}
		
		if($aRenderList === true) {
			$ret .= '<ul>';
		}
		
		foreach($categories as $cat) {
			if($aRenderList === true) {
				$ret .= '<li><a href="' . $od_eshop_wpplugin->get_main_page_url() . '&amp;cat_id=' . $cat['ID'] .
								'"' . (($cat['ID'] == $aSelectedCatId) ? ' class="selected"' : '') . '>' .
								$cat['title'] . '</a></li>';
			} else {
				$ret .= '<a href="' . $od_eshop_wpplugin->get_main_page_url() . '&amp;cat_id=' . $cat['ID'] . '"' .
								(($cat['ID'] == $aSelectedCatId) ? ' class="selected"' : '') . '>' .
								$cat['title'] . '</a> &nbsp;|&nbsp; ';
			}
		}
		
		if($aRenderList === true) {
			$ret .= '</ul>';
		}
		
		return $ret;
	}
	
}
